<?php
/**
 * Class: Comparecouse
 * This Class is used to compare between two or more courses.
 * @author ovo
 *
 */
class Community_ComparecourseController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    	
    }

    public function indexAction(){
        // action body
        $this->view->headTitle("Please choose your school", 'PREPEND');
    	
        $recs = new Community_Model_DbTable_coursedetails();
        $list = $recs->getDistinctSchools();
        //print_r($list);
       //Pagination control on the page
        $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($list));
        $paginator->setItemCountPerPage(5)
        		  ->setCurrentPageNumber($this->_getParam('page', 1));
       
      $this->view->paginator = $paginator;
    }
    
    public function selectAction(){
    	$this->view->headTitle("Choose course Instances", 'PREPEND');
    	
    	$form = new Community_Form_compare();
    	$form->setAction($this->getFrontController()->getBaseUrl() . '/community/Comparecourse/compare');
    	$this->view->form = $form;
    }
    public function compareAction()
    {
    	 $this->view->headTitle("Plot of comparison between both courses", 'PREPEND');
    	
        // action body
        $f = new Community_Model_comparecourse();
        $courses = $this->_getAllParams();
        $g = new Community_Model_DbTable_coursedetails();
        $this->view->name1=  $g->fetchAll('id ='.$courses['course']);
        $this->view->name2 = $g->fetchAll('id ='. $courses['course2']);
        $det = $f->compare($courses['course'], $courses['semester'], $courses['year'], $courses['course2'], $courses['semester2'], $courses['year2']);
      	$this->pagination($det[0], 1);
      	$this->pagination2($det[1], 1);
      	$this->view->date1 = $courses['semester'] .", " .$courses['year'];
      	$this->view->date2 = $courses['semester2'] .", " .$courses['year2'];
      }

    
		private function pagination($resultset, $count){
        $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($resultset));
        $paginator->setItemCountPerPage($count)	        
        		  ->setCurrentPageNumber($this->_getParam('page', 1));
        $this->view->paginator = $paginator;
		}

		private function pagination2($resultset, $count){
        $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($resultset));
        $paginator->setItemCountPerPage($count)	        
        		  ->setCurrentPageNumber($this->_getParam('page', 1));
        $this->view->paginator2 = $paginator;
		}

}
